#include "myExtension.h"

MyExtension::MyExtension(QWidget *parent)
    : QWidget(parent)
{
    setWindowTitle("MyExtension_拓展对话框");

    //创建基本窗体：
    createBaseWidget();
    //创建拓展窗体：
    createDetailWidget();


   QVBoxLayout* mainLayout = new QVBoxLayout(this);
    mainLayout->addWidget(baseWidget);
    mainLayout->addWidget(detailWidget);

    //设置容器大小：
    mainLayout->setSizeConstraint(QLayout::SetFixedSize);        //设置窗体大小不能被拖拽改变；

}

MyExtension::~MyExtension()
{
}

//创建基本窗体：
void MyExtension::createBaseWidget()
{
    //sb别tm忘了写：
    baseWidget = new QWidget;


    //性名：
    QLabel* name_label = new QLabel("name>");
    QLineEdit* name = new QLineEdit;

    //性别：
    QLabel* sex_label = new QLabel("sex>");
    QComboBox* sex = new QComboBox;
    sex->insertItem(0,"man");
    sex->insertItem(1,"woman");
    sex->insertItem(2,"gay");

    //栅格布局：
    QGridLayout* gridlayout = new QGridLayout;
    gridlayout->addWidget(name_label,0,0);
    gridlayout->addWidget(name,0,1);
    gridlayout->addWidget(sex_label,1,0);
    gridlayout->addWidget(sex,1,1);

    //按钮：
    QPushButton* okbtn = new QPushButton("ok");
    QPushButton* tuozhanbtn = new  QPushButton("详细");
#if BUTTON_BOX_IS
                    //按钮也有盒子，可以使按钮安排布局：
     QDialogButtonBox* buttonbox = new QDialogButtonBox(Qt::Vertical);       //Vertical——设置方向，这是水平方向
     buttonbox->addButton(okbtn,QDialogButtonBox::ActionRole);
                                                      //QDialogButtonBox::ActionRole  3 Clicking the button causes changes to the elements within the dialog——单击该按钮会导致对话框中的元素发生更改。
     buttonbox->addButton(tuozhanbtn,QDialogButtonBox::ActionRole);
#else
                    //传统方法：
    QVBoxLayout* buttonlayout=  new QVBoxLayout;
    buttonlayout->addWidget(okbtn);
    buttonlayout->addWidget(tuozhanbtn);
#endif

    QHBoxLayout* mainlayout = new QHBoxLayout(baseWidget);
    mainlayout->addLayout(gridlayout);
#if BUTTON_BOX_IS
    mainlayout->addWidget(buttonbox);
#else
    mainlayout->addLayout(buttonlayout);
#endif


    connect(tuozhanbtn,SIGNAL(clicked(bool)),this,SLOT(showDetailWidget()));
}
//创建拓展窗体：
void MyExtension::createDetailWidget()
{
    detailWidget = new QWidget;


    //年龄：
    QLabel* age_label = new QLabel("年龄>");
    QSpinBox* age = new QSpinBox;
    age->setRange(0,100);

    //部门：
    QLabel* depatement_label = new QLabel("部门");
    QComboBox*depatement = new QComboBox;
    depatement->insertItem(0,"c部门");
    depatement->insertItem(1,"java部门");
    depatement->insertItem(2,"游戏部门");

    //栅格布局：
    QGridLayout* gridlayout = new QGridLayout(detailWidget);
    gridlayout->addWidget(age_label,0,0);
    gridlayout->addWidget(age,0,1);
    gridlayout->addWidget(depatement_label,1,0);
    gridlayout->addWidget(depatement,1,1);

    //先隐藏：
    detailWidget->hide();

}

//显示详细信息窗体：
void MyExtension::showDetailWidget()
{
    if(detailWidget->isHidden())
        detailWidget->show();
   else
        detailWidget->hide();
}

